package com.weimob.mcloud.wechatwork.customer.export.sentinel;

import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.weimob.mcloud.wechatwork.common.enums.CommonBizErrorEnum;
import com.weimob.mcloud.wechatwork.common.enums.MainBizDomainEnum;
import com.weimob.mcloud.wechatwork.common.enums.SubBizDomainEnum;
import com.weimob.mcloud.wechatwork.common.utils.BizErrorCodeGenerator;
import com.weimob.mcloud.wechatwork.customer.service.user.base.PaasBaseResponse;
import com.weimob.mcloud.wechatwork.customer.service.user.base.PageResponse;
import com.weimob.mcloud.wechatwork.customer.service.user.module.bo.customer.*;
import com.weimob.mcloud.wechatwork.customer.service.user.module.bo.group.CorpChatGroupListBO;
import com.weimob.mcloud.wechatwork.customer.service.user.module.bo.group.CorpChatGroupListOpenBO;
import com.weimob.mcloud.wechatwork.customer.service.user.module.bo.group.CorpChatGroupMemberOpenBO;
import com.weimob.mcloud.wechatwork.customer.service.user.module.dto.customer.CustomerDetailDTO;
import com.weimob.mcloud.wechatwork.customer.service.user.module.dto.customer.CustomerIdGetDTO;
import com.weimob.mcloud.wechatwork.customer.service.user.module.dto.customer.ExternalUserInfoByWidsDTO;
import com.weimob.mcloud.wechatwork.customer.service.user.module.dto.customer.openapi.CustomerLoseApi;
import com.weimob.mcloud.wechatwork.customer.service.user.module.dto.customer.openapi.ExternalUserInfoApi;
import com.weimob.mcloud.wechatwork.customer.service.user.module.dto.customer.openapi.ExternalUserInfoByWidsApi;
import com.weimob.mcloud.wechatwork.customer.service.user.module.dto.group.CorpChatGroupQueryOpenDTO;
import com.weimob.mcloud.wechatwork.customer.service.user.module.dto.group.CustomerChatGroupDTO;
import com.weimob.mcloud.wechatwork.customer.service.user.module.dto.group.CustomerGroupMemberQueryOpenDTO;
import com.weimob.mcloud.wechatwork.customer.service.user.module.dto.group.CustomerGroupPassDTO;
import com.weimob.mcloud.wechatwork.customer.service.user.utils.PaasResponseUtil;
import com.weimob.soa.common.response.SoaResponse;
import com.weimob.soa.common.utils.SoaUtil;

import java.util.Collections;
import java.util.List;

/**
 * @author chenliuzhu
 * @date 2023/4/6
 */
public class SentinelCommonBlockHandler {


    /**
     * 客户群列表-openApi 限流handler
     *
     * @param dto
     * @param ex
     * @return
     */
    public static SoaResponse<PageResponse<CorpChatGroupListOpenBO>, ?> customerGroupListForOpenBlockHandler(CorpChatGroupQueryOpenDTO dto, BlockException ex) {
        String code = BizErrorCodeGenerator.generate(MainBizDomainEnum.CUSTOMER_MANAGEMENT
                , SubBizDomainEnum.GROUP_MANAGEMENT, CommonBizErrorEnum.SYSTEM_BUSY);
        return SoaUtil.error(code, CommonBizErrorEnum.SYSTEM_BUSY.getDesc(), new PageResponse<>(Collections.emptyList()));
    }

    /**
     * 单个群聊下群成员列表-openApi 限流handler
     * @param dto
     * @param ex
     * @return
     */
    public static SoaResponse<PageResponse<CorpChatGroupMemberOpenBO>, ?> memberListForOpenBlockHandler(CustomerGroupMemberQueryOpenDTO dto, BlockException ex) {
        String code = BizErrorCodeGenerator.generate(MainBizDomainEnum.CUSTOMER_MANAGEMENT
                , SubBizDomainEnum.GROUP_MANAGEMENT, CommonBizErrorEnum.SYSTEM_BUSY);
        return SoaUtil.error(code, CommonBizErrorEnum.SYSTEM_BUSY.getDesc(), new PageResponse<>(Collections.emptyList()));
    }

    /**
     * 根据客户wid查询客户群信息列表-openApi 限流handler
     * @param dto
     * @param ex
     * @return
     */
    public static SoaResponse<PageResponse<CorpChatGroupListBO>, ?> getGroupChatListByWidBlockHandler(CustomerChatGroupDTO dto, BlockException ex) {
        String code = BizErrorCodeGenerator.generate(MainBizDomainEnum.CUSTOMER_MANAGEMENT
                , SubBizDomainEnum.GROUP_MANAGEMENT, CommonBizErrorEnum.SYSTEM_BUSY);
        return SoaUtil.error(code, CommonBizErrorEnum.SYSTEM_BUSY.getDesc(), new PageResponse<>(Collections.emptyList()));
    }

    /**
     * 根据wid获取客户群相关信息-openApi 限流handler
     * @param dto
     * @param ex
     * @return
     */
    public static PaasBaseResponse<PageResponse<CorpChatGroupListBO>> getCustomerGroupsByWidsBlockHandler(CustomerGroupPassDTO dto, BlockException ex) {
        String code = BizErrorCodeGenerator.generate(MainBizDomainEnum.CUSTOMER_MANAGEMENT
                , SubBizDomainEnum.GROUP_MANAGEMENT, CommonBizErrorEnum.SYSTEM_BUSY);
        return PaasResponseUtil.error(code, CommonBizErrorEnum.SYSTEM_BUSY.getDesc(), new PageResponse<>(Collections.emptyList()));
    }

    /**
     * 查询外部联系人列表-openApi 限流handler
     * @param api
     * @param ex
     * @return
     */
    public static SoaResponse<CustomerPageResponse<ExternalUserListBO>, ?>  queryExternalUserListBlockHandler(ExternalUserInfoApi api, BlockException ex) {
        String code = BizErrorCodeGenerator.generate(MainBizDomainEnum.CUSTOMER_MANAGEMENT
                , SubBizDomainEnum.CUSTOMER_LIST, CommonBizErrorEnum.SYSTEM_BUSY);
        return SoaUtil.error(code, CommonBizErrorEnum.SYSTEM_BUSY.getDesc(), new CustomerPageResponse<>(Collections.emptyList()));
    }

    /**
     * 根据批量wid获取员工和客户关系信息-openApi 限流handler
     * @param api
     * @param ex
     * @return
     */
    public static SoaResponse<List<CustomerRelationBO>, ?> queryCustomerRelationBlockHandler(ExternalUserInfoByWidsApi api, BlockException ex) {
        String code = BizErrorCodeGenerator.generate(MainBizDomainEnum.CUSTOMER_MANAGEMENT
                , SubBizDomainEnum.CUSTOMER_LIST, CommonBizErrorEnum.SYSTEM_BUSY);
        return SoaUtil.error(code, CommonBizErrorEnum.SYSTEM_BUSY.getDesc(), Collections.emptyList());
    }


    /**
     * 通过wid查询客户员工关系数据-限流handler
     *
     * @param dto
     * @param ex
     * @return
     */
    public static PaasBaseResponse<List<ExternalUserRelationBO>> getRelationByWidsBlockHandler(ExternalUserInfoByWidsDTO dto, BlockException ex) {
        String code = BizErrorCodeGenerator.generate(MainBizDomainEnum.CUSTOMER_MANAGEMENT
                , SubBizDomainEnum.CUSTOMER_LIST, CommonBizErrorEnum.SYSTEM_BUSY);
        return PaasResponseUtil.error(code, CommonBizErrorEnum.SYSTEM_BUSY.getDesc(), Collections.emptyList());
    }


    /**
     * 查询客户详情-限流handler
     *
     * @param dto
     * @param ex
     * @return
     */
    public static  SoaResponse<CustomerDetailBO, ?> queryCustomerDetailBlockHandler(CustomerDetailDTO dto, BlockException ex) {
        String code = BizErrorCodeGenerator.generate(MainBizDomainEnum.CUSTOMER_MANAGEMENT
                , SubBizDomainEnum.CUSTOMER_LIST, CommonBizErrorEnum.SYSTEM_BUSY);
        return SoaUtil.error(code, CommonBizErrorEnum.SYSTEM_BUSY.getDesc(), null);
    }


    /**
     * 查询流失客户列表- openApi 限流handler
     *
     * @param dto
     * @param ex
     * @return
     */
    public static SoaResponse<CustomerPageResponse<CustomerLoseLogBO>, ?> queryLoseListBlockHandler(CustomerLoseApi dto, BlockException ex) {
        String code = BizErrorCodeGenerator.generate(MainBizDomainEnum.CUSTOMER_MANAGEMENT
                , SubBizDomainEnum.CUSTOMER_LIST, CommonBizErrorEnum.SYSTEM_BUSY);
        return SoaUtil.error(code, CommonBizErrorEnum.SYSTEM_BUSY.getDesc(), new CustomerPageResponse<>(Collections.emptyList()));
    }

    /**
     * 查询客户基础数据- 限流handler
     *
     * @param dto
     * @param ex
     * @return
     */
    public static SoaResponse<CustomerDetailBO, ?> getCustomerBaseInfoBlockHandler(CustomerIdGetDTO dto, BlockException ex) {
        String code = BizErrorCodeGenerator.generate(MainBizDomainEnum.CUSTOMER_MANAGEMENT
                , SubBizDomainEnum.CUSTOMER_LIST, CommonBizErrorEnum.SYSTEM_BUSY);
        return SoaUtil.error(code, CommonBizErrorEnum.SYSTEM_BUSY.getDesc(), null);
    }

    /**
     * 查询客户基础数据list- 限流handler
     *
     * @param dto
     * @param ex
     * @return
     */
    public static SoaResponse<List<CustomerDetailBO>, ?> getCustomerBaseInfoListBlockHandler(CustomerIdGetDTO dto, BlockException ex) {
        String code = BizErrorCodeGenerator.generate(MainBizDomainEnum.CUSTOMER_MANAGEMENT
                , SubBizDomainEnum.CUSTOMER_LIST, CommonBizErrorEnum.SYSTEM_BUSY);
        return SoaUtil.error(code, CommonBizErrorEnum.SYSTEM_BUSY.getDesc(), Collections.emptyList());
    }
}
